<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="st" uri="http://www.springframework.org/tags"%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>扑通扑通</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<c:set var="ctx" value="" />
<link rel="stylesheet"
	href="${ctx}/static/resource/css/theme.css?version=0.1">
<script src="${ctx}/static/resource/js/jquery-2.2.4.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

</head>

<body>  
    <form action="" method="post" >  
     <div>您将支付  ${totalprice} 元</div>
    <input type="hidden" name="openid" id="openid" value="${openid}"/>
      <input type="hidden" name="ordercode" id="ordercode" value="${ordercode}"/>
        <div  class="order-box" value="确认支付" name="ajaxLoadId" id="confirmtopay">确认支付</div>  
    </form>  
    <script type="text/javascript">  
    var basePath = "<%=request.getContextPath()%>";  
    $("#confirmtopay").click(function(){  
    
        var openid=$("#openid").val();
        var ordercode=$("#ordercode").val();
        var url="/paytest/payconfig.do?openid="+openid+"&ordercode="+ordercode ;
        alert(url);
        $.ajax({  
        	type: "GET",
            url:url           //<span style="font-family:微软雅黑;">ajax调用微信统一接口获取prepayId</span>  
            
        }).done(function(data){  
        	alert(JSON.stringify(data));
            var obj = eval('(' + data + ')');  
            if(parseInt(obj.agent)<5){  
                alert("您的微信版本低于5.0无法使用微信支付");  
                return;  
            }  
            WeixinJSBridge.invoke('getBrandWCPayRequest',{  
                "appId" : obj.appId,                  //公众号名称，由商户传入  
                "timeStamp":obj.timeStamp,          //时间戳，自 1970 年以来的秒数  
                "nonceStr" : obj.nonceStr,         //随机串  
                "package" : obj.packageValue,      //商品包信息
                "signType" : obj.signType,        //微信签名方式:  
                "paySign" : obj.paySign           //微信签名  
                },function(res){      
                    alert(res.err_msg);  
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {  
                    window.location.href=obj.sendUrl;  
                }else{  
                    alert("fail");  
                    window.location.href="http://www.shuguangwang.cn/authfailed.do";     
                                       //<span style="font-family:微软雅黑;">当失败后，继续跳转该支付页面让用户可以继续付款，贴别注意不能直接调转jsp，</span><span style="font-size:10.5pt">不然会报</span><span style="font-size:12.0pt"> system:access_denied。</span>  
                }  
            });  
              
        });  
    });  
    </script>  
  </body> 
</html>